import VueRouter from "vue-router";


const routes = [
    {
        path: '/',
        name:'long',
        component: () => import('../components/Login')
    
    },
    {
        path: '/Index',
        name:'index',
        component: () => import('../components/Index'),
        children:[
            {
                path: '/Main',
                name:'main',
                component: () => import('../components/Main')
            
            },
            {
                path: '/Form',
                name:'form',
                component: () => import('../components/Form')
            
            }
        ]
    
    }
    
]

const router = new VueRouter({
    mode: 'history',
    routes
})

router.beforeEach((to, from, next) => {
    const curUser  = localStorage.getItem('CurUser');
    if(curUser==null){
        if (to.path !== '/') {  
            router.replace('/');  
        } else {  
            // 如果已经在根路由，则正常前进  
            next();  
        }  
    }else{
        next();
    }
})

export default router